/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Francisco
 */
@Entity
@Table(name = "consumidor_vivienda")
@DiscriminatorValue("VIVIENDA")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ConsumidorVivienda.findAll", query = "SELECT c FROM ConsumidorVivienda c"),
    @NamedQuery(name = "ConsumidorVivienda.findByIdConsumidor", query = "SELECT c FROM ConsumidorVivienda c WHERE c.idConsumidor = :idConsumidor")})
public class ConsumidorVivienda extends Consumidor implements Serializable {
    private static final long serialVersionUID = 1L;
    @JoinTable(name = "habitantes_vivienda", joinColumns = {
        @JoinColumn(name = "id_consumidor_vivienda", referencedColumnName = "id_consumidor_vivienda")}, inverseJoinColumns = {
        @JoinColumn(name = "id_persona", referencedColumnName = "id_persona")})
    @ManyToMany
    private List<Persona> personaList;
    @JoinColumn(name = "id_direccion", referencedColumnName = "id_direccion")
    @ManyToOne(optional = false)
    private Direccion idDireccion;

    public ConsumidorVivienda() {
    }

    public ConsumidorVivienda(Integer idConsumidor) {
        this.setIdConsumidor(idConsumidor);
    }

    @XmlTransient
    public List<Persona> getPersonaList() {
        return personaList;
    }

    public void setPersonaList(List<Persona> personaList) {
        this.personaList = personaList;
    }

    public Direccion getIdDireccion() {
        return idDireccion;
    }

    public void setIdDireccion(Direccion idDireccion) {
        this.idDireccion = idDireccion;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getIdConsumidor() != null ? getIdConsumidor().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ConsumidorVivienda)) {
            return false;
        }
        ConsumidorVivienda other = (ConsumidorVivienda) object;
        if ((this.getIdConsumidor() == null && other.getIdConsumidor() != null) || (this.getIdConsumidor() != null && !this.getIdConsumidor().equals(other.getIdConsumidor()))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.ConsumidorVivienda[ idConsumidorVivienda=" + getIdConsumidor() + " ]";
    }
    
}
